<?php
/**
 * @Name 业务基类
 * @Auther 宋博
 * @Date 2021/4/21 15:42
 */

namespace Modules\Common\Services;
use Modules\Common\Exceptions\ApiException;

class CommonServices
{
    public function __construct(){

    }
    /**
     * @Name api成功返回
     * @Description
     * @Author 宋博
     * @Date 2021/4/21 16:13
     * @Param data.code 状态
     * @Param data.message 信息
     * @Return Json
     */
    public function apiSuccess($data=[]){
        $data['status'] = 1;
        if(!isset($data['code'])){
            $data['code'] = 200;
        }
        if(!isset($data['message'])){
            $data['message'] = '成功!';
        }
        return response()->json($data,200);
    }
    /**
     * @Name  api失败返回
     * @Description
     * @Author 宋博
     * @Date 2021/4/21 16:13
     * @Param data.code 状态
     * @Param data.message 信息
     * @Return Json
     */
    public function apiError($data=[]){
        $data['status'] = 0;
        if(!isset($data['code'])){
            $data['code'] = 400;
        }
        if(!isset($data['message'])){
            $data['message'] = '失败！';
        }
        throw new ApiException($data);
    }

}
